#ifndef FACEACTION_H
#define FACEACTION_H

#include <QObject>
#include <QtQml/QtQml>
#include <QVector>
#include <QRect>
#include <QWaitCondition>
#include "facedetector.h"
#include "cameravideobuffer.h"
class FaceAction : public QThread
{
    Q_OBJECT
    Q_ENUMS(ACTION_TYPE)
    Q_PROPERTY(ACTION_TYPE actionType READ actionType WRITE setActionType)
    Q_PROPERTY(QObject* videobuf READ videobuf WRITE setVideobuf)

signals:
    void FaceDetected(QVector<QRect>);
public:
    enum ACTION_TYPE{
        ACTION_IDLE,
        ACTION_DETECT,
        ACTION_EXTRACT,
        ACTION_SCAN
    };
    explicit FaceAction(QObject *parent = 0);
    ACTION_TYPE actionType() const{
        return mType;
    }
    void setActionType(ACTION_TYPE type){
        if(mType==type)
            return;
        mLock.lock();
        mType=type;
        if(mType!=ACTION_IDLE)
            mWait.wakeAll();
        mLock.unlock();
    }

    QObject* videobuf()const
    {
        return mCameraBuf;
    }
    void setVideobuf(QObject* o)
    {
        mCameraBuf=qobject_cast<CameraVideoBuffer*>(o);
    }

private:
    void run();
    bool Init();
    void doDetect();
    void doExtract(){}
    void doCompare(){}

    ACTION_TYPE mType;
    FaceDetector* mDetector;
    CameraVideoBuffer* mCameraBuf;


    QWaitCondition mWait;
    QMutex mLock;
};

#endif // FACEACTION_H
